
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>生命周期钩子 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="component.html" />
    
    
    <link rel="prev" href="zu-jian-yu-mo-ban.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Angular-cli/">
            
                <a href="../Angular-cli/">
            
                    
                    Angular-cli
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Angular-cli/Angular-cli.html">
            
                <a href="../Angular-cli/Angular-cli.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Angular-cli/restMenu.html">
            
                <a href="../Angular-cli/restMenu.html">
            
                    
                    初始结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../architecture/">
            
                <a href="../architecture/">
            
                    
                    架构
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../architecture/mo-kuai.html">
            
                <a href="../architecture/mo-kuai.html">
            
                    
                    模块简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../architecture/component.html">
            
                <a href="../architecture/component.html">
            
                    
                    组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../architecture/Service.html">
            
                <a href="../architecture/Service.html">
            
                    
                    服务与依赖注入
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="./">
            
                <a href="./">
            
                    
                    组件与模板
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="zu-jian-yu-mo-ban.html">
            
                <a href="zu-jian-yu-mo-ban.html">
            
                    
                    数据显示与模板语法
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.2" data-path="cycle.html">
            
                <a href="cycle.html">
            
                    
                    生命周期钩子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="component.html">
            
                <a href="component.html">
            
                    
                    组件交互
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="style.html">
            
                <a href="style.html">
            
                    
                    组件样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="dynamic.html">
            
                <a href="dynamic.html">
            
                    
                    动态组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="directive.html">
            
                <a href="directive.html">
            
                    
                    属性指令与结构指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="pipeAndAnimit.html">
            
                <a href="pipeAndAnimit.html">
            
                    
                    管道与动画
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../router/">
            
                <a href="../router/">
            
                    
                    路由与导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../form/">
            
                <a href="../form/">
            
                    
                    表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../http/">
            
                <a href="../http/">
            
                    
                    请求http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../project/">
            
                <a href="../project/">
            
                    
                    项目解析:结构目录
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >生命周期钩子</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x751F;&#x547D;&#x5468;&#x671F;&#x94A9;&#x5B50;">&#x751F;&#x547D;&#x5468;&#x671F;&#x94A9;&#x5B50;</h3>
<p> &#x6BCF;&#x4E2A;&#x7EC4;&#x4EF6;&#x90FD;&#x6709;&#x4E00;&#x4E2A;&#x88AB; Angular &#x7BA1;&#x7406;&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x3002;</p>
<p> Angular &#x521B;&#x5EFA;&#x5B83;&#xFF0C;&#x6E32;&#x67D3;&#x5B83;&#xFF0C;&#x521B;&#x5EFA;&#x5E76;&#x6E32;&#x67D3;&#x5B83;&#x7684;&#x5B50;&#x7EC4;&#x4EF6;&#xFF0C;&#x5728;&#x5B83;&#x88AB;&#x7ED1;&#x5B9A;&#x7684;&#x5C5E;&#x6027;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x68C0;&#x67E5;&#x5B83;&#xFF0C;&#x5E76;&#x5728;&#x5B83;&#x4ECE; DOM &#x4E2D;&#x88AB;&#x79FB;&#x9664;&#x524D;&#x9500;&#x6BC1;&#x5B83;&#x3002;</p>
<p> Angular &#x63D0;&#x4F9B;&#x4E86;&#x751F;&#x547D;&#x5468;&#x671F;&#x94A9;&#x5B50;&#xFF0C;&#x628A;&#x8FD9;&#x4E9B;&#x5173;&#x952E;&#x751F;&#x547D;&#x65F6;&#x523B;&#x66B4;&#x9732;&#x51FA;&#x6765;&#xFF0C;&#x8D4B;&#x4E88;&#x4F60;&#x5728;&#x5B83;&#x4EEC;&#x53D1;&#x751F;&#x65F6;&#x91C7;&#x53D6;&#x884C;&#x52A8;&#x7684;&#x80FD;&#x529B;&#x3002;</p>
<p> &#x9664;&#x4E86;&#x90A3;&#x4E9B;&#x7EC4;&#x4EF6;&#x5185;&#x5BB9;&#x548C;&#x89C6;&#x56FE;&#x76F8;&#x5173;&#x7684;&#x94A9;&#x5B50;&#x5916;,&#x6307;&#x4EE4;&#x6709;&#x76F8;&#x540C;&#x751F;&#x547D;&#x5468;&#x671F;&#x94A9;&#x5B50;&#x3002;</p>
   <table>
      <thead>
         <tr>
            <th>&#x94A9;&#x5B50;</th>
            <th>&#x7528;&#x9014;&#x53CA;&#x65F6;&#x673A;</th>
         </tr>   
      </thead>
      <tbody>
         <tr>
            <td>ngOnChanges()</td>
            <td> &#x5F53; Angular&#xFF08;&#x91CD;&#x65B0;&#xFF09;&#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x8F93;&#x5165;&#x5C5E;&#x6027;&#x65F6;&#x54CD;&#x5E94;&#x3002; &#x8BE5;&#x65B9;&#x6CD5;&#x63A5;&#x53D7;&#x5F53;&#x524D;&#x548C;&#x4E0A;&#x4E00;&#x5C5E;&#x6027;&#x503C;&#x7684; SimpleChanges &#x5BF9;&#x8C61; <br>
                 &#x5F53;&#x88AB;&#x7ED1;&#x5B9A;&#x7684;&#x8F93;&#x5165;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x8C03;&#x7528;&#xFF0C;&#x9996;&#x6B21;&#x8C03;&#x7528;&#x4E00;&#x5B9A;&#x4F1A;&#x53D1;&#x751F;&#x5728; ngOnInit() &#x4E4B;&#x524D;
            </td>
         </tr>  
         <tr>
            <td>ngOnInit()</td>
            <td> &#x5728; Angular &#x7B2C;&#x4E00;&#x6B21;&#x663E;&#x793A;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x548C;&#x8BBE;&#x7F6E;&#x6307;&#x4EE4;/&#x7EC4;&#x4EF6;&#x7684;&#x8F93;&#x5165;&#x5C5E;&#x6027;&#x4E4B;&#x540E;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x6307;&#x4EE4;/&#x7EC4;&#x4EF6;&#x3002;<br>
                 &#x5728;&#x7B2C;&#x4E00;&#x8F6E; ngOnChanges() &#x5B8C;&#x6210;&#x4E4B;&#x540E;&#x8C03;&#x7528;&#xFF0C;&#x53EA;&#x8C03;&#x7528;&#x4E00;&#x6B21;&#x3002;
            </td>
         </tr>  
         <tr>
            <td>ngDoCheck()</td>
            <td> &#x5F53; Angular&#xFF08;&#x91CD;&#x65B0;&#xFF09;&#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x8F93;&#x5165;&#x5C5E;&#x6027;&#x65F6;&#x54CD;&#x5E94;&#x3002; &#x8BE5;&#x65B9;&#x6CD5;&#x63A5;&#x53D7;&#x5F53;&#x524D;&#x548C;&#x4E0A;&#x4E00;&#x5C5E;&#x6027;&#x503C;&#x7684; SimpleChanges &#x5BF9;&#x8C61; <br>
                 &#x5F53;&#x88AB;&#x7ED1;&#x5B9A;&#x7684;&#x8F93;&#x5165;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x8C03;&#x7528;&#xFF0C;&#x9996;&#x6B21;&#x8C03;&#x7528;&#x4E00;&#x5B9A;&#x4F1A;&#x53D1;&#x751F;&#x5728; ngOnInit() &#x4E4B;&#x524D;
            </td>
         </tr>  
         <tr>
            <td>ngAfterContentInit()</td>
            <td> &#x5F53;&#x628A;&#x5185;&#x5BB9;&#x6295;&#x5F71;&#x8FDB;&#x7EC4;&#x4EF6;&#x4E4B;&#x540E;&#x8C03;&#x7528;&#x3002;<br>
                 &#x7B2C;&#x4E00;&#x6B21; ngDoCheck() &#x4E4B;&#x540E;&#x8C03;&#x7528;&#xFF0C;&#x53EA;&#x8C03;&#x7528;&#x4E00;&#x6B21;&#x3002;
            </td>
         </tr>  
         <tr>
            <td>ngAfterContentChecked()</td>
            <td> &#x6BCF;&#x6B21;&#x5B8C;&#x6210;&#x88AB;&#x6295;&#x5F71;&#x7EC4;&#x4EF6;&#x5185;&#x5BB9;&#x7684;&#x53D8;&#x66F4;&#x68C0;&#x6D4B;&#x4E4B;&#x540E;&#x8C03;&#x7528;&#x3002;<br>
                 ngAfterContentInit() &#x548C;&#x6BCF;&#x6B21; ngDoCheck() &#x4E4B;&#x540E;&#x8C03;&#x7528;
            </td>
         </tr>     
         <tr>
            <td>ngAfterViewInit()</td>
            <td> &#x521D;&#x59CB;&#x5316;&#x5B8C;&#x7EC4;&#x4EF6;&#x89C6;&#x56FE;&#x53CA;&#x5176;&#x5B50;&#x89C6;&#x56FE;&#x4E4B;&#x540E;&#x8C03;&#x7528;&#x3002;<br>
                &#x7B2C;&#x4E00;&#x6B21; ngAfterContentChecked() &#x4E4B;&#x540E;&#x8C03;&#x7528;&#xFF0C;&#x53EA;&#x8C03;&#x7528;&#x4E00;&#x6B21;&#x3002;
            </td>
         </tr>       
         <tr>
            <td>ngAfterViewChecked()</td>
            <td> &#x6BCF;&#x6B21;&#x505A;&#x5B8C;&#x7EC4;&#x4EF6;&#x89C6;&#x56FE;&#x548C;&#x5B50;&#x89C6;&#x56FE;&#x7684;&#x53D8;&#x66F4;&#x68C0;&#x6D4B;&#x4E4B;&#x540E;&#x8C03;&#x7528;&#x3002;&#x3002;<br>
                ngAfterViewInit() &#x548C;&#x6BCF;&#x6B21; ngAfterContentChecked() &#x4E4B;&#x540E;&#x8C03;&#x7528;&#x3002;
            </td>
         </tr>       
         <tr>
            <td>ngOnDestroy()</td>
            <td> &#x5F53; Angular &#x6BCF;&#x6B21;&#x9500;&#x6BC1;&#x6307;&#x4EE4;/&#x7EC4;&#x4EF6;&#x4E4B;&#x524D;&#x8C03;&#x7528;&#x5E76;&#x6E05;&#x626B;&#x3002; &#x5728;&#x8FD9;&#x513F;&#x53CD;&#x8BA2;&#x9605;&#x53EF;&#x89C2;&#x5BDF;&#x5BF9;&#x8C61;&#x548C;&#x5206;&#x79BB;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x5668;&#xFF0C;&#x4EE5;&#x9632;&#x5185;&#x5B58;&#x6CC4;&#x6F0F;&#x3002;<br>
                 &#x5728; Angular &#x9500;&#x6BC1;&#x6307;&#x4EE4;/&#x7EC4;&#x4EF6;&#x4E4B;&#x524D;&#x8C03;&#x7528;&#x3002;
            </td>
         </tr>          
      </tbody>

   </table>

<p>&#x7EC4;&#x4EF6;&#x6240;&#x6709;&#x94A9;&#x5B50;&#x6267;&#x884C;&#x987A;&#x5E8F;</p>
<p>   <img src="../assets/peek-a-boo.png" alt=""></p>
<p> &#x65E5;&#x5FD7;&#x4FE1;&#x606F;&#x7684;&#x65E5;&#x5FD7;&#x548C;&#x6240;&#x89C4;&#x5B9A;&#x7684;&#x94A9;&#x5B50;&#x8C03;&#x7528;&#x987A;&#x5E8F;&#x662F;&#x4E00;&#x81F4;&#x7684;&#xFF1A; <code>OnChanges&#x3001;OnInit&#x3001;DoCheck (3x)&#x3001;AfterContentInit&#x3001;AfterContentChecked (3x)&#x3001; AfterViewInit&#x3001;AfterViewChecked (3x)&#x548C; OnDestroy</code> </p>
<p> &#x6784;&#x9020;&#x51FD;&#x6570;(<code>constructor</code>)&#x4E2D;&#x9664;&#x4E86;&#x4F7F;&#x7528;&#x7B80;&#x5355;&#x7684;&#x503C;&#x5BF9;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x8FDB;&#x884C;&#x521D;&#x59CB;&#x5316;&#x4E4B;&#x5916;&#xFF0C;&#x4EC0;&#x4E48;&#x90FD;&#x4E0D;&#x5E94;&#x8BE5;&#x505A;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="zu-jian-yu-mo-ban.html" class="navigation navigation-prev " aria-label="Previous page: 数据显示与模板语法">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="component.html" class="navigation navigation-next " aria-label="Next page: 组件交互">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"生命周期钩子","level":"1.4.2","depth":2,"next":{"title":"组件交互","level":"1.4.3","depth":2,"path":"comAndtem/component.md","ref":"comAndtem/component.md","articles":[]},"previous":{"title":"数据显示与模板语法","level":"1.4.1","depth":2,"path":"comAndtem/zu-jian-yu-mo-ban.md","ref":"comAndtem/zu-jian-yu-mo-ban.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["fontsettings","sharing","lunr","search","highlight","livereload"],"pluginsConfig":{"fontsettings":{"family":"sans","size":2,"theme":"white"},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"search":{},"highlight":{},"livereload":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"comAndtem/cycle.md","mtime":"2018-06-14T03:08:17.380Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-06-29T06:02:19.129Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    

    </body>
</html>

